{extend name="public:base" /}{block name="css"}
<link href="/static/laydate/theme/default/laydate.css">{/block}{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h3>总订单金额：{$all_pay_price}元</h3>
                </div>

                <div class="ibox-content">
                    <div class="row search-form">
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请输入手机号" name="mobile" value="{:input('mobile')}" type="text" class="form-control form-control-lg">
                            </div>
                        </div>

                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请选择开始日期" type="text" name="start_time" value="{:input('start_time')}" class="form-control form-control-lg screen-date" readonly>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请选择结束日期" type="text" name="end_time" value="{:input('end_time')}" class="form-control form-control-lg screen-date" readonly>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="status" class="form-control form-control-lg">
                                    <option value="-1">请选择订单状态</option>
                                    <option value="0" {:input(
                                    'status') === '0' ? 'selected' : ''}>待支付</option>
                                    <option value="1" {:input(
                                    'status') == 1 ? 'selected' : ''}>进行中</option>
                                    <option value="2" {:input(
                                    'status') == 2 ? 'selected' : ''}>已完成</option>
                                    <option value="3" {:input(
                                    'status') == 3 ? 'selected' : ''}>审核中</option>
                                    <option value="4" {:input(
                                    'status') == 4 ? 'selected' : ''}>已取消</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <button type="button" class="btn btn-primary btn-lg screen-btn">搜索</button>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>会员昵称</th>
                                <th>会员手机号</th>
                                <th>订单号</th>
                                <th>总金额</th>
                                <th>支付金额</th>
                                <th>订单状态</th>
                                <th>任务状态</th>
                                <th>支付时间</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.nickname}</td>
                                <td>{$vo.mobile}</td>
                                <td>{$vo.order_sn}</td>
                                <td>{$vo.all_price}</td>
                                <td>{$vo.pay_price}</td>
                                <td>{$vo.status_text}</td>
                                <td>{$vo.plan_status_text}</td>
                                <td>{:timeFormat($vo.pay_time)}</td>
                                <td>{:timeFormat($vo.create_time)}</td>
                                <td class="project-actions">
                                    <a href="{:url('doOrder', ['id' => $vo.id])}" class="btn btn-white btn-sm">
                                        <i class="iconfont icon-edit"></i> 详情
                                    </a>
                                    {if $vo.status == 3}
                                    <a class="btn btn-white btn-sm" onclick="logId({$vo.id})" data-toggle="modal" data-target="#plan"><i class="iconfont icon-users"></i> 分配任务
                                    </a>
                                    {/if}
                                    {if $vo.plan_status == 2}
                                    <a href="{:url('confirmSettlement', ['id' => $vo.id])}" class="btn btn-white btn-sm ajax-operate"><i class="iconfont icon-success"></i> 确认结算
                                    </a>
                                    {/if}
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {if !empty($list)}{$list->render()}{/if}
                    </div>

                </div>
            </div>
        </div>

        <!--    修改密码弹框    -->
        <div class="modal inmodal" id="plan" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content animated flipInY">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                        </button>
                        <h4 class="modal-title">选择陪诊员</h4>
                    </div>
                    <div class="modal-body">
                        <input type="text" class="form-control" oninput="changeValue(this)" style="margin-bottom: 10px" placeholder="请输入昵称或手机号">

                        <select class="form-control user-select">

                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white close-model" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="confirm">确认</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script src="/static/laydate/laydate.js"></script>
<script>
    laydate.render({
        elem: '.screen-date' //指定元素
    });

    var user_list = `{$user_list}` ? JSON.parse(`{$user_list}`) : [];
    var order_id = 0;

    function logId(id) {
        order_id = id;
    }

    chooseUser();
    function chooseUser() {
        var option = createOption(user_list);
        $('.user-select').html(option);
    }

    function createOption(list) {
        var option = '<option value="0">请选择</option>';
        list.forEach(val => {
            option += `<option value="${val.id}">${val.username} / ${val.mobile}</option>`;
        })

        return option;
    }

    function changeValue(that) {
        var new_user_list = [];
        var screen = $(that).val();

        if (screen !== '') {
            user_list.forEach(val => {
                if (val.username.indexOf(screen) != -1 || val.mobile.indexOf(screen) != -1) {
                    new_user_list.push(val);
                }
            })
        } else {
            new_user_list = user_list;
        }

        var option = createOption(new_user_list);

        $('.user-select').html(option);
    }

    $('#confirm').click(function (){
        var user_id = parseInt($('.user-select').val());
        confirmChoose(user_id);
    })

    function confirmChoose(user_id) {
        var user_id = parseInt(user_id);
        if (user_id == 0) {
            layer.msg('请选择陪诊员', {icon: 2});
            return false;
        }

        $.post("/index/Api/chooseUser", {id: order_id, user_id: user_id}, res => {
            if (res.result == 1) {
                layer.msg(res.msg, {icon: 1}, () => {
                    window.location.reload();
                });
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'json')
    }
</script>{/block}

